#namespace("com.htwy.core.model.Role")
  #sql("findByCondition")
    SELECT uuid, name, sign, rank, dataLevel, status, serial, orgnazation, creator, createTime, mender, modifyTime, deletedBy, deletedMarker, deleteTime
    FROM ht_sys_role
    #WHERE()
      #if(uuid)
        uuid = #para(uuid)
      #end
      #if(name)
        AND name = #para(name)
      #end
      #if(sign)
        AND sign = #para(sign)
      #end
      #if(rank)
        AND rank = #para(rank)
      #end
      #if(dataLevel)
        AND dataLevel = #para(dataLevel)
      #end
      #if(status)
        AND status = #para(status)
      #end
      #if(serial)
        AND serial = #para(serial)
      #end
      #if(orgnazation)
        AND orgnazation = #para(orgnazation)
      #end
      #if(creator)
        AND creator = #para(creator)
      #end
      #if(createTime)
        AND createTime = #para(createTime)
      #end
      #if(mender)
        AND mender = #para(mender)
      #end
      #if(modifyTime)
        AND modifyTime = #para(modifyTime)
      #end
      #if(deletedBy)
        AND deletedBy = #para(deletedBy)
      #end
      #if(deletedMarker)
        AND deletedMarker = #para(deletedMarker)
      #end
      #if(deleteTime)
        AND deleteTime = #para(deleteTime)
      #end
    #end
    ORDER BY serial asc
    
  #end

  #sql("deleteByPks")
    DELETE FROM ht_sys_role
    #WHERE()
      #if(pks != null && pks.length > 0)
        #if(pks.length>1)
          uuid in (
          #for(tempId : pks)
            #if(for.first)
              #para(tempId)
            #else
              , #para(tempId)
            #end
          #end
          )
        #else
          uuid = #para(pks[0])
        #end
      #end
    #end
  #end

  #sql("removeRelationByUserIdsAndRoleId")
    DELETE FROM ht_sys_r_account_role
    #WHERE()
      #if(userIds != null && userIds.length > 0)
        #if(userIds.length>1)
          accountId in (
            #for(tempId : userIds)
              #if(for.first)
                #para(tempId)
              #else
                , #para(tempId)
              #end
            #end
          )
        #else
          accountId = #para(userIds[0])
        #end
      #end
      AND roleId = #para(roleId)
    #end
  #end

  #sql("updateStatus")
    UPDATE ht_sys_role
    SET status = #para(status)
    #WHERE()
      #if(roleIds != null && roleIds.length > 0)
        #if(roleIds.length>1)
          uuid in (
            #for(tempId : roleIds)
              #if(for.first)
                #para(tempId)
              #else
                , #para(tempId)
              #end
            #end
          )
        #else
          uuid = #para(roleIds[0])
        #end
      #end
    #end
  #end

  #sql("getPermissionIdsById")
    SELECT permissionId FROM ht_sys_r_role_permission WHERE roleId = #para(uuid)
  #end

  #sql("deletePermissionsByRoleId")
    DELETE FROM ht_sys_r_role_permission WHERE roleId = #para(roleId)
  #end

  #sql("addRolePermissions")
    INSERT INTO ht_sys_r_role_permission (roleId, permissionId) 
    VALUES 
    #if(permissionIds != null && permissionIds.length > 0)
      #for(permissionId : permissionIds)
        #if(for.first)
          (#para(roleId), #para(permissionId))
        #else
          , (#para(roleId), #para(permissionId))
        #end
      #end
    #end
  #end

#end